<template>
  <div class="container">
    <xy-table
      :api="api"
      :columns="columns"
      :param="args"
      @selection-change="selectionChange"
      ref="table"
    >
      <template #addItem>
        <!-- <el-button icon="el-icon-plus" @click="showAddDialog">添加</el-button> -->
        <search-header
          :model="args"
          :on-search="onSearch"
        >
          <template #operation>
            <el-form-item class="col-1">
              <el-button
                @click="toSign"
                size="mini"
              >{{ $language.local("委托授权签约") }}</el-button>
            </el-form-item>
          </template>
        </search-header>
      </template>
      <template #selection>
        <el-table-column
          align="center"
          type="selection"
        ></el-table-column>
      </template>

      <template #edit>
        <span hidden></span>
      </template>
      <template #authsign="{ row }">
        <template v-if="row.zt === -1">
          <el-button
            @click="toSign([row.Id])"
            size="mini"
            type="text"
          >{{ $language.local("委托授权签约") }}</el-button>
        </template>
        <span
          hidden
          v-else
        ></span>
      </template>
      <template
        #setrm="{ row }"
        class="center"
      >
        <el-button
          @click="setRM(row)"
          size="mini"
          type="text"
          v-if="row.EmpRM === -1"
        >{{ $language.local("纳入授信") }}</el-button>
      </template>
      <template #downfile="{ row }">
        <template v-if="row.SignFileDownUrl">
          <el-button
            @click="downloadFile(row)"
            type="text"
          >{{ $language.local("下载协议") }}</el-button>
        </template>
      </template>
    </xy-table>
  </div>
</template>

<script>
import API from "../../plugins/api";
export default {
  inject: ["reload"],
  data() {
    return {
      data: {
        list: [],
        total: 0,
      },

      api: new API("/api/employeeSign/"),
      param: {
        BeginDate: "2020/1/1",
      },
      queryColumn: "merchantName",

      columns: {
        EmpName: "李孝正",
        IdCardNo: "4310000000000073",
        EmpPhone: "13308479086",
        // BankCardNo: "",
        MerchantName: "淮北通财网络服务有限公司",
        // ServiceName: "湖南好捷科技有限公司",

        BeginDate: "2021-03-24",
        EndDate: "2022-03-24",

        // zt: -1,
        zt: "待签约",
        // AuditStatus: "",
        Indate: "",
        // SignNo: "T2103240002",
        // Indate: "2021/3/24 16:55:00",
        // employeeId: 1702,
        // MID: 130,
        // EmpNo: "E21022411261073",

        // signWayCN: "自行签约",
        // ServiceContent: "004021",
        // SignName: "",
        // BankCardNo: "6226097310246971",
        // AuditStatus: "待认证",
        // EmpRM: -1,
        // SignFileDownUrl: null,
      },
      Ids: null,
      args: {
        sid: "",
        mid: "",
        BeginDate: "2021-1-1",
        EndDate: "",
        Verify: "",
        status: "",
      },
    };
  },
  methods: {
    onSearch(e) {
      // this.params = e;
      console.log(e);
      console.log(this.$refs.table);
      this.$refs.table.getData(e);
    },
    downloadAgreement(e) {
      console.log(e);
      if (e.SignFileDownUrl) {
        let url = e.SignFileDownUrl.replace(";", ":");
        window.location.href = url;
      }
    },
    async setRM(row) {
      console.log(row);
      let query = {
        mid: row.MID,
        empid: row.employeeId,
      };
      await this.$http.post(`/api/employeeSign/SetRM/${row.Id}`, null, query);

      this.$router.replace("/PersonalCreditList");
      // this.reload();
    },
    selectionChange(res) {
      this.Ids = Array.from(res, (v) => v.Id);
    },
    async toSign() {
      console.log(this.Ids);
      if (!this.Ids) {
        return this.$message.error("请选择灵工再进行委托签约！");
      }
      let Ids = this.Ids.join("#");
      console.log(Ids);
      // if (!Ids) {
      //   return this.$message.error("请先选择灵工再授权！");
      // }
      await this.$http.post(`/api/employeeSign/ToSign?Ids=${Ids}`);
      this.reload();
    },
  },
};
</script>

<style></style>
